package com.bow.syntax

/**
  * @author vv
  * @since 2017/7/24.
  */
// 样例类
case class PersonCase(name: String, age: Int)


object CaseDemo {

  def matchTest(x: Int): String = x match {
    case 1 => "one"
    case 2 => "two"
    case _ => "many"
  }

  def main(args: Array[String]) {

    // object 的成员都是静态的因此可以直接调用
    println(matchTest(3)) // many

    val alice = new PersonCase("Alice", 25)
    val bob = new PersonCase("Bob", 32)
    val charlie = new PersonCase("Charlie", 32)

    for (person <- List(alice, bob, charlie)) {
      person match {
        case PersonCase("Alice", 25) => println("Hi Alice!")
        case PersonCase("Bob", 32) => println("Hi Bob!")
        case PersonCase(name, age) =>
          println("Age: " + age + " year, name: " + name + "?")
      }
    }
  }

}
